package bastanteo.servlet.cliente;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

 

 

import bastanteo.excepcion.DAOExcepcion;
import bastanteo.excepcion.RegistrarExcepcion;
 
import bastanteo.modelo.Cliente;
import bastanteo.negocio.ClienteNegocio;

/**
 * Servlet implementation class ServletInsert
 */
@WebServlet("/ClienteInsertServlet")
public class ClienteInsertServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ClienteInsertServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
 
		String codClie 	= request.getParameter("txtcodcli");
		String ruc 	= request.getParameter("txtruc");
		String razSoc	= request.getParameter("txtrsoc");
		String fecInicOper  = request.getParameter("txtfini");
		String tipoEmp = "SA"; //request.getParameter("lstTipoemp");		
		int cantEmp = 1;
	 
		ClienteNegocio  negocio = new ClienteNegocio();
		try {
			
			
			String ret = negocio.insertarCliente(codClie, ruc, razSoc, fecInicOper, tipoEmp, cantEmp);
			//negocio.insertarCliente("C121","83","Cliente 07 SA","01/01/2010","SA",12);
			
			if (ret=="found"){
					RequestDispatcher rd = request.getRequestDispatcher("error_ruc.jsp");
					
					rd.forward(request, response);
					return; 
			}
			RequestDispatcher rd = request.getRequestDispatcher("sucesfull.jsp");			
			rd.forward(request, response);
			//response.sendRedirect(request.getContextPath()	+ "/ClienteBuscarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);

		} catch (RegistrarExcepcion e) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		



	}
 

}
